package databinding.demo.ui;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

import databinding.demo.R;
import databinding.demo.adapter.ListViewAdapter;
import databinding.demo.adapter.RecyclerViewAdapter;
import databinding.demo.databinding.ActivityBindSeniorBinding;
import databinding.demo.model.EmployeeInfo;
import databinding.demo.utils.DataUtils;

/**
 * Created by dengdayi
 * Date: 2017/03/28 15：08
 * databinding -高级
 */

public class BindSeniorActivity extends AppCompatActivity {

    ActivityBindSeniorBinding binding;
    private ListViewAdapter mAdapter;
    private List<EmployeeInfo> mEmployeeInfos;

    private RecyclerViewAdapter mRecyclerViewAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_bind_senior);
        mEmployeeInfos = new ArrayList<>();
        mEmployeeInfos.addAll(DataUtils.getEmployees());
        //ListView的使用
        mAdapter = new ListViewAdapter(this, mEmployeeInfos);
        binding.setAdapter(mAdapter);
        //RecyclerView的使用
        LinearLayoutManager layoutManager = new GridLayoutManager(this, 2);
        binding.mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerViewAdapter = new RecyclerViewAdapter(mEmployeeInfos);
        binding.mRecyclerView.setAdapter(mRecyclerViewAdapter);
    }
}
